package com.want.buss.interfaces.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.want.buss.interfaces.po.BankAccountInfo;
import com.want.buss.interfaces.po.DepositMethod;
import com.want.buss.interfaces.webService.DTREQDepositService;
import com.want.buss.interfaces.webService.DTREQDepositService.DEPOSITMESSAGE;
import com.want.buss.interfaces.webService.DTRESDepositService;
import com.want.buss.interfaces.webService.SIODepositServiceService;
import com.want.buss.interfaces.webService.DTREQDepositService.BANKACCOUNTINFO;
import com.want.buss.interfaces.webService.DTREQDepositService.DEPOSITDETAILLIST;
import com.want.buss.interfaces.webService.DTREQDepositService.DEPOSITDETAILLIST.MAP.ENTRY;
import com.want.buss.interfaces.webService.DTREQDepositService.ATTACHMENTLIST;

/**
 * @description 调用接口service
 * @author 00114260
 * @version V1.0.0
 */
public class WebServiceUtil {
	
	/**
	 * @author 00114260
	 * @serialData 2018/01/22
	 * @description 客户入金抛转BPM生成表单
	 * @param moneyDeposit
	 * @param bankAccountInfo
	 * @param moneyTypeDetailList
	 * @param moneyCertificatesList
	 * @return
	 */
	public static Map<String, Object> sendDepositInfo(DepositMethod moneyDeposit, BankAccountInfo moneyBank,
            List<Map<String, Object>> moneyTypeDetailList, List<Map<String, Object>> moneyCertificatesList) {
	    DTREQDepositService req = new DTREQDepositService();
	    
	    // 传入入金单信息
	    DEPOSITMESSAGE depositMessage = new DEPOSITMESSAGE();
	    depositMessage.setAPPLICATIONEMPID(getObjectValue(moneyDeposit.getCustomerId()));
	    depositMessage.setBPMID(getObjectValue(moneyDeposit.getBpmId()));
	    depositMessage.setCHECKOPTION(getObjectValue(moneyDeposit.getCheckOption()));
	    depositMessage.setCHECKSTATUS(getObjectValue(moneyDeposit.getCheckStatus()));
	    depositMessage.setCHECKTIME(getObjectValue(moneyDeposit.getCheckTime()));
	    depositMessage.setCOMPANYID(getObjectValue(moneyDeposit.getCompanyId()));
	    depositMessage.setCOMPANYNAME(getObjectValue(moneyDeposit.getCompanyName()));
	    depositMessage.setCUSTOMERID(getObjectValue(moneyDeposit.getCustomerId()));
	    depositMessage.setCUSTOMERNAME(getObjectValue(moneyDeposit.getCustomerName()));
	    depositMessage.setDEPOSITSTATUS(getObjectValue(moneyDeposit.getDepositStatus()));
	    depositMessage.setINPUTTIME(getObjectValue(moneyDeposit.getInputTime()));
	    depositMessage.setSID(getObjectValue(moneyDeposit.getSid()));
	    depositMessage.setTOTALAMOUNT(getObjectValue(moneyDeposit.getTotalAmount()));
	    DTREQDepositService.DEPOSITMESSAGE.MAP depositMap = new DTREQDepositService.DEPOSITMESSAGE.MAP();
	    depositMessage.setMAP(depositMap);
	    req.setDEPOSITMESSAGE(depositMessage);
	    
	    // 传入银行账户信息
	    BANKACCOUNTINFO bankaccountinfo = new BANKACCOUNTINFO();
	    bankaccountinfo.setBANKACCOUNT(getObjectValue(moneyBank.getBankAccount()));
	    bankaccountinfo.setBANKNAME(getObjectValue(moneyBank.getBankName()));
	    bankaccountinfo.setBANKSERIESNUMBER(getObjectValue(moneyBank.getBankSeriesNumber()));
	    bankaccountinfo.setCUSTOMERBANKACCOUNT(getObjectValue(moneyBank.getCustomerBankAccount()));
	    bankaccountinfo.setCUSTOMERBANKNAME(getObjectValue(moneyBank.getCustomerBankName()));
	    bankaccountinfo.setCUSTOMERBANKNO(getObjectValue(moneyBank.getCustomerBankNo()));
	    bankaccountinfo.setCUSTOMERHOUSEHOLDER(getObjectValue(moneyBank.getCustomerHouseholder()));
	    bankaccountinfo.setDEPOSITSID(getObjectValue(moneyBank.getDepositSid()));
	    bankaccountinfo.setHOUSEHOULDER(getObjectValue(moneyBank.getHouseholder()));
	    bankaccountinfo.setISCUSTOMERSAME(getObjectValue(moneyBank.getIsCustomerSame()));
	    bankaccountinfo.setSID(getObjectValue(moneyBank.getSid()));
	    BANKACCOUNTINFO.MAP bankaccountMap = new DTREQDepositService.BANKACCOUNTINFO.MAP();
	    bankaccountinfo.setMAP(bankaccountMap);
	    req.setBANKACCOUNTINFO(bankaccountinfo);
	
	    // 传入入金单明细
	    for (int i = 0; i < moneyTypeDetailList.size(); i++) {
	    	Map<String, Object> map = moneyTypeDetailList.get(i);
		    DEPOSITDETAILLIST depositDetailList = new DEPOSITDETAILLIST();
		    depositDetailList.setAMOUNT(getObjectValue(map.get("AMOUNT")));
		    depositDetailList.setCHANNELID(getObjectValue(map.get("CHANNEL_ID")));
		    depositDetailList.setDEPOSITSID(getObjectValue(map.get("DEPOSIT_SID")));
		    depositDetailList.setMARGINAMOUNTTYPE(getObjectValue(map.get("MARGIN_AMOUNT_TYPE")));
		    depositDetailList.setMONEYTYPE(getObjectValue(map.get("MONEY_TYPE")));
		    depositDetailList.setNOTICEBUSSEMPID(getObjectValue(map.get("NOTICE_BUSS_EMP_ID")));
		    depositDetailList.setNOTICEDIRECTOREMPID(getObjectValue(map.get("NOTICE_DIRECTOR_EMP_ID")));
		    depositDetailList.setORDERNO(getObjectValue(map.get("ORDER_NO")));
		    depositDetailList.setORDERNODESC(getObjectValue(map.get("ORDER_NO_DESC")));
		    depositDetailList.setSID(getObjectValue(map.get("SID")));
		    depositDetailList.setSPECIALFUNDMONEY(getObjectValue(map.get("SPECIAL_FUND_MONEY")));
		    depositDetailList.setSPECIALFUNDNAME(getObjectValue(map.get("SPECIAL_FUND_NAME")));
		    depositDetailList.setSPECIALFUNDNO(getObjectValue(map.get("SPECIAL_FUND_NO")));
		    DTREQDepositService.DEPOSITDETAILLIST.MAP depositDetailMap = new DTREQDepositService.DEPOSITDETAILLIST.MAP();
		    ENTRY ENTRY = new ENTRY();
		    ENTRY.setKEY("MONEY_TYPE_NAME");
		    ENTRY.setVALUE(getObjectValue(map.get("MONEY_TYPE_NAME")));
		    ENTRY.setKEY("CHANNEL_NAME");
		    ENTRY.setVALUE(getObjectValue(map.get("CHANNEL_NAME")));
		    depositDetailMap.setENTRY(ENTRY);
		    depositDetailList.setMAP(depositDetailMap);
		    req.getDEPOSITDETAILLIST().add(depositDetailList);
	    }
	    
	    // 传入入金单凭证
	    for (int i = 0; i < moneyCertificatesList.size(); i++) {
	    	Map<String, Object> map = moneyCertificatesList.get(i);
		    ATTACHMENTLIST attachmentlist = new ATTACHMENTLIST();
		    attachmentlist.setCERTIFICATESNAME(getObjectValue(map.get("CERTIFICATES_NAME")));
		    attachmentlist.setCERTIFICATESNO(getObjectValue(map.get("CERTIFICATES_NO")));
		    attachmentlist.setDEPOSITSID(getObjectValue(map.get("DEPOSIT_SID")));
		    attachmentlist.setPATH(getObjectValue(map.get("PATH")));
		    attachmentlist.setSIZE(getObjectValue(map.get("FILESIZE")));
		    DTREQDepositService.ATTACHMENTLIST.MAP attachmentMap = new DTREQDepositService.ATTACHMENTLIST.MAP();
		    attachmentlist.setMAP(attachmentMap);
		    req.getATTACHMENTLIST().add(attachmentlist);
	    }
	    SIODepositServiceService sioDepositService1 = new SIODepositServiceService();
	    DTRESDepositService res = sioDepositService1.getHTTPPort().siODepositService(req);
	    DTRESDepositService.RETURN returns = res.getRETURN();
	    Map<String, Object> map = new HashMap<String, Object>();
	    map.put("code", returns.getCODE());
	    map.put("message", returns.getMSG());
	    return map;
	}
	
	public static String getObjectValue(Object value) {
		return value != null && !"".equals(value) ? value.toString() : "";
	}

}
